package com.hongkang.springtrains.web;

import com.hongkang.springtrains.web.exception.UserNotFoundException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * 控制器共享异常处理器
 */
@ControllerAdvice
public class MyExceptionHandler {


    @ExceptionHandler(value = UserNotFoundException.class)
    @ResponseStatus(value = HttpStatus.NOT_FOUND)
    public Error userNotFoundException(UserNotFoundException ex){
        Error error = new Error(ex.getUserID(),ex.getMessage());
        return  error;
    }









}
